function OnLoad () {
    var hypers = __selectElements(document, ".//hypernode")[0]; //seleziona hypernodes locali 
    var tweets_client = __selectElements(document, ".//div[@id='tweets_cl']")[0]; //seleziona div tweets del client
    var tweets_server = __selectElements(hypers, ".//div[@class='tweet']"); //seleziona tweet remoti
    
    var action = function (event) {
        alert(event.relatedNode.innerHTML);
        tweets_client.innerHTML = event.relatedNode.innerHTML;
    };

    __registerEventListener(hypers, ".", "DOMNodeInserted", action)
    //Client registrato agli eventi di modifica del sottoalbero tweets_server del server
    //__registerEventListener(hypers[0], ".", "DOMNodeInserted", action);
    
    for (n in tweets_server){
        tweets_client.appendChild(tweets_server[n]);
    }
 }

function AddTweet() {
    var msg = __selectElements(document, ".//textarea[@name='message']")[0];
    var hypernode = __selectElements(document, ".//hypernode")[0];
    var tweets = __selectElements(hypernode, ".")[0];
    
    var new_tweet = document.createElement("div");
    new_tweet.setAttribute("class","tweet");
    new_tweet.innerHTML = msg.value;
    
    tweets.insertBefore(new_tweet,tweets.firstChild);
    
    tweets.commit();
}